package weixinkeji.dev.power.center.service;

import java.util.List;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.power.center.bean.SysP;
import weixinkeji.dev.power.center.bean.SysUR;
import weixinkeji.dev.power.center.so.URPSQL;

/**
 *
 * @author IMY
 */
public class URPService {

    /**
     * 获得用户所有权限（直接权限，拥有角色的权限）
     *
     * @param uID
     * @return
     */
    public static List<SysP> getURByUserID(String uID) {
//        String uID = a.request.getParameter("uID");
        //用户的角色集合。
        List<SysUR> sv = Dao.selectVast(SysUR.class, Where.putThenGet(Where.TJ_IGNORE_NOTHING, SysUR.class, "", "user_id", "=", uID));

        StringBuilder sb = new StringBuilder();
        String rolesID;
        for (SysUR obj : sv) {
            sb.append(",'").append(obj.getRole_id()).append("'");
        }
        rolesID = sb.length() == 0 ? "''" : sb.substring(1);
        //角色集合
        //s List<SysRole> lrole = Dao.selectVast(SysRole.class, TJ.putIN(SysRole.class, null, "role_id", rolesID));//sb.length() == 0 ? new ArrayList<>() : 
        //用户直接权限集合
        List<SysP> up = Dao.selectVast_My(SysP.class, URPSQL.SELECT_UP_USERID.replace("?1", uID));
        //角色集合的权限集合
        List<SysP> rp = Dao.selectVast_My(SysP.class, URPSQL.SELECT_RP_ROLEID.replace("?1", rolesID));
        for (SysP obj : up) {
            rp.add(obj);
        }
        return rp;
    }
}
